import Mock from "mockjs";
import MockParamsUtil from "@/utils/MockParamsUtil";
import MockPageUtil from "@/utils/MockPageUtil";

let parentCode
let {sysParamDetailList} = Mock.mock({
"sysParamDetailList|1-10": [
{
id: "@increment(1)",
parentCode,
detailCode: "@integer(1, 100)",
"detailName": "@cword(1,6)",
paramRemark: "@sentence(5, 10)",
paramRemark2: "@sentence(5, 10)",
}
]
})

/**
* 分页查询数据
* @param params    参数
*/
Mock.mock(new RegExp("/sysParamDetail/page*"), 'post', (options) => {
const dataJson = JSON.parse(options.body);
console.log(dataJson, 'dataJson')
const page = dataJson.page
parentCode = dataJson.parentCode
// 过滤查询条件
sysParamDetailList = MockPageUtil.filterList(sysParamDetailList, dataJson, "parentCode");
// 分页
const data = MockPageUtil.sliceList(sysParamDetailList, page.current, page.pageSize);
return {
code: 200,
msg: 'success',
data
}
})
// 新增
Mock.mock(new RegExp('/sysParamDetail/add*'), 'post', (options) => {
debugger
const body = JSON.parse(options.body)
sysParamDetailList = [
Mock.mock({
id: "@increment(1)",
createBy: "@cname(3)",
createTime: "@now()",
updateBy: "@cname(3)",
updateTime: "@now()",
...body
}),
...sysParamDetailList
]
return {
code: 200,
msg: 'success',
data: '添加成功'
}
})
// 删除
Mock.mock(new RegExp('/sysParamDetail/*'), 'delete', (options) => {
debugger
const id = MockParamsUtil.getPathUrlParams(options.url)
sysParamDetailList = sysParamDetailList.filter(item => item.id != id)
return {
code: 200,
msg: 'success',
data: '删除成功'
}
})
// 获取详情
Mock.mock(new RegExp('/sysParamDetail/*'), 'get', (options) => {
debugger
const id = MockParamsUtil.getPathUrlParams(options.url)
const data = sysParamDetailList.find(item => item.id == id)
return {
code: 200,
msg: 'success',
data
}
})
// 编辑
Mock.mock(new RegExp('/sysParamDetail/edit*'), 'post', (options) => {
const body = JSON.parse(options.body)
if (body.id) {
sysParamDetailList = sysParamDetailList.map(item => {
if (item.id == body.id) {
return body
}
return item
})
} else {
sysParamDetailList = [
Mock.mock({
id: "@increment(1)",
createBy: "@cname(3)",
createTime: "@now()",
updateBy: "@cname(3)",
updateTime: "@now()",
...body
}),
...sysParamDetailList
]
return {
code: 200,
msg: 'success',
data: '添加成功'
}
}

})
